#include "main.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"

//槽
    //接收来自setwindow的数据
void MainWindow::DataFromSetWindow(QString str)
{
    ui->topmsg->setText(str);
    //更新目标日期
    ui->botmsg->setText(QString("%1-%2-%3").arg(T_DATE.year()).arg(T_DATE.month()).arg(T_DATE.day()));
    tim1_Handle();
}

//定时器
    //定时器1周期事件
void MainWindow::tim1_Handle()
{
    int temp = key_val;
    //获取当前日期
    N_DATE = QDate::currentDate();
    key_val = N_DATE.daysTo(T_DATE);

    //显示在界面上
    if(temp != key_val)
    {
        ui->midmsg->setText(QString("%1天").arg(key_val));
    }
}

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //界面初始化
        ui->botmsg->setText(QString("%1-%2-%3").arg(T_DATE.year()).arg(T_DATE.month()).arg(T_DATE.day()));
    //定时器初始化
        tim1 = new QTimer();
        connect(tim1,&QTimer::timeout,this,[=]()
        {
            tim1_Handle();
        });
        tim1_Handle();
        tim1->start(1000);

    //菜单初始化
        connect(ui->setAction,&QAction::triggered,this,[=]()
        {
            emit SendDataToSetWindow(ui->topmsg->text());
            emit ShowSetWindow();
        });
    //界面刷新

}

MainWindow::~MainWindow()
{
    delete ui;
}

